package cn.tramy.pinxian.wind.handler.dispatch

import cn.tramy.pinxian.wind.handler.HandlerInfo

class DispatchTaskHolder {
    private val tasks: MutableList<DispatchTask> = mutableListOf()

    companion object {
        private val localVar: ThreadLocal<DispatchTaskHolder> = ThreadLocal.withInitial { DispatchTaskHolder() }
        fun current() = localVar.get()
    }

    fun tasks() = tasks.toList()

    fun addTask(handlerInfo: HandlerInfo<Any>, message: Any) {
        this.tasks.add(DispatchTask(handlerInfo, message))
    }

    fun reset() = this.tasks.clear()
}